﻿using System;
using System.Windows.Forms;
using PodpisyElektorniczne.Classes;
using PodpisyElektorniczne.Interfaces;

namespace PodpisyElektorniczne
{
    public partial class frmLogging : Form
    {
        private LoggedIn log;
        public frmLogging()
        {
            log = Program.Log;    
            InitializeComponent();
        }

        private void btn_regin_Click(object sender, EventArgs e)
        {
            frmReginstration f= new frmReginstration();
            this.Hide();
            f.ShowDialog();
            if (f.CancelButton.DialogResult == DialogResult.Cancel)
            {
                f.Dispose();
                this.Show();
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                if (log.TryToLogin(txt_log.Text, txt_pass.Text))
                {
                    this.Hide();
                    
                    Settings.UserLogin = txt_log.Text;
                    
                    (new Form1()).ShowDialog();

                }
            }catch(Exception ex)
            {
                MessageBox.Show(@"Problem: " + ex.Message, @"Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }

        private void btn_cancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            var result = MessageBox.Show(@"Try out Appi. You about to see tial verion of SRS appi.", @"Information",
                                         MessageBoxButtons.OK, MessageBoxIcon.Information);
            if(result == DialogResult.OK)
            {
                log.Usser.Name = @"Trial_User";
                log.Usser.Surname = @"Trial_User";
                log.Usser.Pass = @"";
                log.Usser.Login = @"Trial_User";
            }
            this.Hide();
            Settings.UserLogin = log.Usser.Login;
            (new Form1()).ShowDialog();
        }
    }
}
